package com.xxg.renrensearch.dao;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 查询商品Dao
 *
 * @author xuxiaogang
 * @date 2021-11-17
 */
@Mapper
@Component
public interface RenrenShopGoodsDao {

    /**
     * 获取店铺ID最大值
     *
     * @return 结果
     */
    @Select("select max(id) from renren_shop_goods")
    int getMaxId();

    /**
     * 在指定范围内查询数据
     *
     * @param start 开始ID
     * @param end   结束ID
     * @return 结果
     */
    @Select("select id,shop_id as shopId,status,title,sub_title as subTitle,short_title as shortTitle,type,thumb," +
            "thumb_all as thumbAll,video,video_thumb as videoThumb,video_type as videoType,stock,sales," +
            "real_sales as realSales,price,min_price as minPrice,max_price as maxPrice,cost_price as costPrice,original_price as originalPrice," +
            "is_deleted as isDeleted,has_option as hasOption,is_recommand as isRecommand,is_hot as isHot," +
            "is_new as isNew from renren_shop_goods where id between #{start} and #{end}")
    List<RenrenShopGoods> selectByIdRange(@Param("start") int start, @Param("end") int end);

    /**
     * 精确查询商品信息
     *
     * @param id 商品ID
     * @return 结果
     */
    @Select("select id,shop_id as shopId,status,title,sub_title as subTitle,short_title as shortTitle,type,thumb," +
            "thumb_all as thumbAll,video,video_thumb as videoThumb,video_type as videoType,stock,sales," +
            "real_sales as realSales,price,min_price as minPrice,max_price as maxPrice,cost_price as costPrice,original_price as originalPrice," +
            "is_deleted as isDeleted,has_option as hasOption,is_recommand as isRecommand,is_hot as isHot," +
            "is_new as isNew from renren_shop_goods where id = #{id}")
    RenrenShopGoods selectById(@Param("id") int id);

    /**
     * 根据商品ID列表删除记录
     *
     * @param ids ID列表
     */
    @Delete({"<script>",
            "delete from renren_shop_goods where id in ",
            "<foreach collection='ids' item='id' open='(' separator=',' close=')'>",
            "#{id}",
            "</foreach>",
            "</script>"})
    void deleteByIds(@Param("ids") List<Integer> ids);

    @Select({"<script>",
            "select id,shop_id as shopId,status,title,sub_title as subTitle,short_title as shortTitle,type,thumb,",
            "thumb_all as thumbAll,video,video_thumb as videoThumb,video_type as videoType,stock,sales,",
            "real_sales as realSales,price,min_price as minPrice,max_price as maxPrice,cost_price as costPrice,original_price as originalPrice,",
            "is_deleted as isDeleted,has_option as hasOption,is_recommand as isRecommand,is_hot as isHot,",
            "is_new as isNew from renren_shop_goods where id in ",
            "<foreach collection='ids' item='id' open='(' separator=',' close=')'>",
            "#{id}",
            "</foreach>",
            "</script>"})
    List<RenrenShopGoods> selectByIds(@Param("ids") List<Integer> ids);
}